package appliance;

import java.util.Scanner;

interface Appliance{
    abstract int getWeight();
}

class TV implements Appliance{
    int weight;
    public void setWeight(int weight){
        this.weight = weight;
    }
    public int getWeight(){
        return weight;
    }
}
class WashMachine implements Appliance{
    int weight;

    public void setWeight(int weight){
        this.weight = weight;
    }

    public int getWeight(){
        return weight;
    }
}

class AirConditioner implements Appliance{
    int weight;

    public void setWeight(int weight){
        this.weight = weight;
    }

    public int getWeight(){
        return weight;
    }
}

class Truck {
    int sum = 0;
    void add(Appliance appliance){
        sum += appliance.getWeight();
    }

}
public class Main {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        Truck truck = new Truck();
        int n = reader.nextInt();
        int k ,w;
        Appliance []appliances = new Appliance[]{new TV(),new AirConditioner(),new WashMachine()};
        for (int i = 0; i < n; i++) {
            k = reader.nextInt();
            w = reader.nextInt();

            truck.add(appliances[k-1]);
        }

        System.out.println(truck.sum);
    }
}
